package top.fengleifeng.question;

/**
 * @author : fengleifeng
 * @Package top.fengleifeng.question
 * @Description:
 * @date Date : 2021年02月23日 5:07 下午
 */
public class Num1052爱生气的书店老板 {

    class Solution {

        public int maxSatisfied(int[] customers, int[] grumpy, int X) {
            int length = customers.length;
            int normal = 0;
            for (int i = 0; i < length; i++) {
                if (grumpy[i] == 0) {
                    normal += customers[i];
                    customers[i] = 0;
                }
            }
            int max = 0;
            int cur = 0;
            for (int i = 0, j = 0; i < length; i++) {
                cur += customers[i];
                if (i - j + 1 > X) {
                    cur -= customers[j++];
                }
                max = Math.max(max,cur);
            }
            return max + normal;
        }

    }

    public static void main(String[] args) {
        int[] customers = {4, 10, 10};
        int[] grumpy = {1, 1, 0};
        int x = 2;
        int i = new Num1052爱生气的书店老板().new Solution().maxSatisfied(customers, grumpy, x);
        System.out.println(i);
    }
}
